package com.lzq.leetcode.hoot100;

public class s279 {

    public int numSquares(int n) {
        int s = (int)Math.pow((double)n, 0.5);
        int count = 0;
        int[] dp = new int[n + 1];
        for (int i=1; i<=n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }
        dp[0] = 0;

        for (int i=1; i<=n; i++) {
            for (int j=1; j<=s && (i - j * j >= 0); j++) {
                dp[i] = Math.min(dp[i], dp[i - j * j] + 1);
            }
        }

        return dp[n];
    }

    public static void main(String[] args) {
        System.out.println(new s279().numSquares(13));
    }
}
